<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition>
	<h:panelGrid id="orderDetailInputPanel" columns="1"
		rendered="#{orderModel.current != null}" style="border:0px;width:100%">
		<h:panelGrid columns="3" style="width:100%">
			<p:commandButton oncomplete="productDlg.show()" ajax="true"
				update=":dialogForm" actionListener="#{productController.init}"
				icon="add" value="Add" title="Add products"
				style="float:left"></p:commandButton>
			<p:commandButton value="Ordered To Confirmed"
				actionListener="#{orderModel.current.orderedToConfirmed}"
				ajax="true" update="orderDetailInputPanel"
				rendered="#{orderModel.current.isReceived}" style="float:right"></p:commandButton>
			<p:commandButton value="Confirmed To Delivered"
				actionListener="#{orderModel.current.confirmedToDelivered}"
				ajax="true" update="orderDetailInputPanel"
				rendered="#{orderModel.current.isConfirmed}" style="float:right"></p:commandButton>
			<p:selectBooleanCheckbox value="#{orderModel.isCompleteMode}"
				itemLabel="#{msgs.completeMode}" style="float:right">
				<p:ajax event="change" update="orderDetailInputPanel"></p:ajax>
			</p:selectBooleanCheckbox>
		</h:panelGrid>
		<p:dataTable id="orderDetailListTable" var="detail" sortBy="1"
			value="#{orderModel.current.orderDetails}" rows="12" paginator="true"
			paginatorAlwaysVisible="false"
			rowsPerPageTemplate="5,7,10,15,20,30,40,50"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rendered="#{orderModel.isCompleteMode or orderModel.current.isUnknown}"
			style="width:100%">
			<f:facet name="header">						
						Items
				</f:facet>
			<p:columnGroup type="header">
				<p:row>
					<p:column rowspan="2" colspan="2" />
					<p:column colspan="3" headerText="Product" />
					<p:column rowspan="1" colspan="3" headerText="Ordered"
						style="max-width:120px" />
					<p:column rowspan="1" colspan="3" headerText="Confirmed"
						style="max-width:120px" />
					<p:column rowspan="1" colspan="6" headerText="Prepared/Delivered"
						style="max-width:120px" />
				</p:row>

				<p:row>
					<p:column headerText="Number" />
					<p:column headerText="    N  a  m  e    " />
					<p:column headerText="INV." />
					<p:column headerText="QTY." />
					<p:column headerText="Price" />
					<p:column headerText="Sub." />
					<p:column headerText="QTY." />
					<p:column headerText="Price" />
					<p:column headerText="Sub." />
					<p:column headerText="QTY." />
					<p:column headerText="Price" />
					<p:column headerText="Subtotal" />
					<p:column headerText="GST" />
					<p:column headerText="QST" />
					<p:column headerText="Sub.+Tax" />
				</p:row>

			</p:columnGroup>

			<p:column style="width:20px">
				<p:commandButton icon="edit" ajax="true"
					oncomplete="orderDetailDlg.show()" update=":dialogForm">
					<f:setPropertyActionListener value="#{detail}"
						target="#{orderModel.currentOrderDetail}" />
				</p:commandButton>
			</p:column>
			<p:column style="width:20px">
				<p:commandButton icon="delete" ajax="true" update=":detailForm"
					actionListener="#{orderController.removeDetailFromCurrent}">
					<f:setPropertyActionListener value="#{detail}"
						target="#{orderController.removeDetailFromCurrent}" />
				</p:commandButton>
			</p:column>

			<p:column>
				<h:outputText value="#{detail.product.number}" />
			</p:column>
			<p:column sortBy="#{detail.product.name}">
				<h:outputText value="#{detail.product.nameLabel}"
					style="width:520px" />
			</p:column>
			<p:column sortBy="#{detail.product.inventory}">
				<h:outputText
					value="#{detail.product.inventory} #{detail.product.stockUnitLabel}"
					style="width:120px" />
			</p:column>
			<p:column headerText="Quantity">
				<h:outputText
					value="#{detail.orderedQuantity} #{detail.product.stockUnitLabel}" />
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.orderedPrice}/#{detail.product.priceUnitLabel}">

				</h:outputText>

			</p:column>
			<p:column>
				<h:outputText value="#{detail.orderedSubTotal}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column headerText="Quantity">
				<h:outputText
					value="#{detail.confirmedQuantity} #{detail.product.stockUnitLabel}" />
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.confirmedPrice}/#{detail.product.priceUnitLabel}">

				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.confirmedSubTotal}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.deliveredQuantity} #{detail.product.priceUnitLabel}" />
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.deliveredPrice}/#{detail.product.priceUnitLabel}">

				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.deliveredSubTotal}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.deliveredGST}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.deliveredQST}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.deliveredSubTotalPlusTax}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
				</h:outputText>
			</p:column>

			<ui:remove>
				<p:summaryRow>
					<p:column colspan="7" style="text-align:right">
						<h:outputText value="Total:"></h:outputText>
					</p:column>

					<p:column>
						<h:outputText id="orderedTotal"
							value="#{orderModel.current.orderedTotalAmount}"
							style="text-align:right">
							<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
						</h:outputText>
					</p:column>
					<p:column colspan="2" />
					<p:column>
						<h:outputText value="#{orderModel.current.deliveredTotalAmount}"
							style="text-align:right">
							<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
						</h:outputText>
					</p:column>
					<p:column>
						<h:outputText value="#{orderModel.current.deliveredTotalGST}"
							style="text-align:right">
							<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
						</h:outputText>
					</p:column>
					<p:column>
						<h:outputText value="#{orderModel.current.deliveredTotalQST}"
							style="text-align:right">
							<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
						</h:outputText>
					</p:column>
					<p:column>
						<h:outputText value="#{orderModel.current.deliveredTotalPlusTax}"
							style="text-align:right">
							<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
						</h:outputText>
					</p:column>
				</p:summaryRow>
			</ui:remove>
			<p:columnGroup type="footer">
				<p:row>
					<p:column colspan="5" footerText="#{msgs.total}" />
					<p:column footerText="#{orderModel.current.orderedQuantity}" />
					<p:column colspan="1" />
					<p:column
						footerText="#{orderModel.current.orderedTotalAmountLabel}" />
					<p:column footerText="#{orderModel.current.confirmedQuantity}" />
					<p:column colspan="1" />
					<p:column
						footerText="#{orderModel.current.confirmedTotalAmountLabel}" />
					<p:column footerText="#{orderModel.current.deliveredQuantityLabel}" />
					<p:column colspan="1" />
					<p:column
						footerText="#{orderModel.current.deliveredTotalAmountLabel}" />
					<p:column footerText="#{orderModel.current.deliveredTotalGSTLabel}" />
					<p:column footerText="#{orderModel.current.deliveredTotalQSTLabel}" />
					<p:column
						footerText="#{orderModel.current.deliveredTotalPlusTaxLabel}" />
				</p:row>
				<p:row>
					<p:column colspan="16" footerText=" + #{msgs.deliveryFee}"></p:column>
					<p:column
						footerText="#{orderModel.current.deliveryFeeLabel}"></p:column>
				</p:row>
				<p:row>
					<p:column colspan="16" footerText=" - #{msgs.paidByCredit}"></p:column>
					<p:column
						footerText="#{orderModel.current.paidByCreditAmountLabel}"></p:column>
				</p:row>

				<p:row>
					<p:column colspan="16" footerText="#{msgs.charge}"></p:column>
					<p:column
						footerText="#{orderModel.current.deliveredTotalChargeLabel}"></p:column>
				</p:row>
				<p:row rendered="#{orderModel.current.promotionRewardRate>0}">
					<p:column colspan="16"></p:column>
					<p:column
						footerText="#{orderModel.current.promotionRewardRateLabel} #{msgs.creditReward}"></p:column>
				</p:row>
			</p:columnGroup>

		</p:dataTable>



		<p:dataTable id="orderDetailListConfirmTable" var="detail" sortBy="1"
			value="#{orderModel.current.orderDetails}" rows="12" paginator="true"
			paginatorAlwaysVisible="false"
			rowsPerPageTemplate="5,7,10,15,20,30,40,50"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rendered="#{orderModel.isCompleteMode==false and (orderModel.current.isReceived  or orderModel.current.isCanceled)}"
			style="width:100%">
			<p:column style="width:20px">
				<p:commandButton icon="edit" ajax="true"
					oncomplete="orderDetailDlg.show()" update=":dialogForm">
					<f:setPropertyActionListener value="#{detail}"
						target="#{orderModel.currentOrderDetail}" />
				</p:commandButton>
			</p:column>
			<p:column headerText="#{msgs.productNumber}"
				sortBy="#{detail.product.number}">
				<h:outputText value="#{detail.product.number}" />
			</p:column>
			<p:column headerText="#{msgs.productName}"
				sortBy="#{detail.product.name}">
				<h:graphicImage library="images"
					value="../#{detail.product.icon}32.png"></h:graphicImage>
				<h:inputText value="#{detail.product.nameLabel}" readonly="true"
					style="float:right;font-size:1.5em;color:green;font-weight:bold;text-align:right;border:0px" />
			</p:column>
			<p:column headerText="#{msgs.inventory}">
				<h:outputText
					value="#{detail.product.inventory} #{detail.product.stockUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold" />
			</p:column>
			<p:column headerText="#{msgs.orderedQuantity}">
				<h:outputText
					value="#{detail.orderedQuantity} #{detail.product.stockUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold" />
			</p:column>
			<p:column headerText="#{msgs.confirmedQuantity}">
				<h:outputText
					value="#{detail.confirmedQuantity} #{detail.product.stockUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold" />
			</p:column>
			<p:columnGroup type="footer">
				<p:row>
					<p:column colspan="4" footerText="#{msgs.total}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column footerText="#{orderModel.current.orderedQuantity}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column footerText="#{orderModel.current.confirmedQuantity}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
				</p:row>
			</p:columnGroup>
		</p:dataTable>

		<p:dataTable id="orderDetailListPrepareTable" var="detail" sortBy="1"
			value="#{orderModel.current.orderDetails}" rows="12" paginator="true"
			paginatorAlwaysVisible="false"
			rowsPerPageTemplate="5,7,10,15,20,30,40,50"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rendered="#{orderModel.isCompleteMode==false and orderModel.current.isConfirmed==true}"
			style="width:100%">
			<p:column style="width:20px">
				<p:commandButton icon="edit" ajax="true"
					oncomplete="orderDetailDlg.show()" update=":dialogForm">
					<f:setPropertyActionListener value="#{detail}"
						target="#{orderModel.currentOrderDetail}" />
				</p:commandButton>
			</p:column>
			<p:column headerText="#{msgs.productNumber}"
				sortBy="#{detail.product.number}">
				<h:outputText value="#{detail.product.number}" />
			</p:column>
			<p:column headerText="#{msgs.productName}"
				sortBy="#{detail.product.name}">
				<h:graphicImage library="images"
					value="../#{detail.product.icon}32.png"></h:graphicImage>
				<h:inputText value="#{detail.product.nameLabel}" readonly="true"
					style="float:right;font-size:1.5em;color:green;font-weight:bold;text-align:right;border:0px" />
			</p:column>
			<p:column headerText="#{msgs.confirmedQuantity}">
				<h:outputText
					value="#{detail.confirmedQuantity} #{detail.product.stockUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold" />
			</p:column>
			<p:column headerText="#{msgs.deliveredQuantity}">
				<h:outputText
					value="#{detail.deliveredQuantity} #{detail.product.priceUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold"
					rendered="#{detail.product.isCanCaculateExactAmount  and !detail.isConfirmedQuantityMoreThanOne}" />
				<h:outputText
					value="#{detail.deliveredQuantity} #{detail.product.priceUnitLabel}"
					style="font-size:1.2em;color:brown;font-weight:bold"
					rendered="#{detail.product.isCanCaculateExactAmount  and detail.isConfirmedQuantityMoreThanOne}" />
				<h:panelGroup rendered="#{!detail.product.isCanCaculateExactAmount}">
					<h:outputText value="#{detail.deliveredQuantity}"
						style="font-size:1.2em;color:red;font-weight:bold">
						<f:convertNumber type="number" maxFractionDigits="2"
							minFractionDigits="2" />
					</h:outputText>
					<h:outputText value="#{detail.product.priceUnitLabel}"
						style="font-size:1.2em;color:red;font-weight:bold" />
				</h:panelGroup>

			</p:column>
			<p:columnGroup type="footer">
				<p:row>
					<p:column colspan="3" footerText="#{msgs.total}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column footerText="#{orderModel.current.confirmedQuantity}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column footerText="#{orderModel.current.deliveredQuantityLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
				</p:row>
			</p:columnGroup>
		</p:dataTable>


		<p:dataTable id="orderDetailListDeliverTable" var="detail" sortBy="1"
			value="#{orderModel.current.orderDetails}" rows="12" paginator="true"
			paginatorAlwaysVisible="false"
			rowsPerPageTemplate="5,7,10,15,20,30,40,50"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rendered="#{orderModel.isCompleteMode==false and (orderModel.current.isPrepared or orderModel.current.isDelivered or orderModel.current.isPaid or orderModel.current.isPickuped)}"
			style="width:100%">
			<p:column style="width:20px">
				<p:commandButton icon="edit" ajax="true"
					oncomplete="orderDetailDlg.show()" update=":dialogForm">
					<f:setPropertyActionListener value="#{detail}"
						target="#{orderModel.currentOrderDetail}" />
				</p:commandButton>
			</p:column>
			<p:column headerText="#{msgs.productNumber}"
				sortBy="#{detail.product.number}">
				<h:outputText value="#{detail.product.number}" />
			</p:column>
			<p:column headerText="#{msgs.productName}"
				sortBy="#{detail.product.name}">
				<h:graphicImage library="images"
					value="../#{detail.product.icon}32.png"></h:graphicImage>
				<h:inputText value="#{detail.product.nameLabel}" readonly="true"
					style="float:right;font-size:1.5em;color:green;font-weight:bold;text-align:right;border:0px" />
			</p:column>

			<p:column headerText="#{msgs.deliveredQuantity}">
				<h:outputText
					value="#{detail.deliveredQuantity} #{detail.product.priceUnitLabel}"
					style="font-size:1.2em;color:green;font-weight:bold"
					rendered="#{detail.product.isCanCaculateExactAmount  and !detail.isConfirmedQuantityMoreThanOne}">
				</h:outputText>
				<h:outputText
					value="#{detail.deliveredQuantity} #{detail.product.priceUnitLabel}"
					style="font-size:1.2em;color:brown;font-weight:bold"
					rendered="#{detail.product.isCanCaculateExactAmount  and detail.isConfirmedQuantityMoreThanOne}">
				</h:outputText>
				<h:panelGroup rendered="#{!detail.product.isCanCaculateExactAmount}">
					<h:outputText value="#{detail.deliveredQuantity}"
						style="font-size:1.2em;color:red;font-weight:bold">
						<f:convertNumber type="number" maxFractionDigits="2"
							minFractionDigits="2" />
					</h:outputText>
					<h:outputText value="#{detail.product.priceUnitLabel}"
						style="font-size:1.2em;color:red;font-weight:bold">
					</h:outputText>
				</h:panelGroup>
			</p:column>
			<p:column headerText="#{msgs.price}">
				<h:outputText value="#{detail.deliveredPrice}"
					style="font-size:1.2em;color:green;font-weight:bold">
					<f:convertNumber type="number" maxFractionDigits="2"
						minFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column headerText="#{msgs.subtotal}">
				<h:outputText value="#{detail.deliveredSubTotal}"
					style="font-size:1.2em;color:green;font-weight:bold">
					<f:convertNumber type="number" maxFractionDigits="2"
						minFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column headerText="#{msgs.GST}"
				rendered="#{orderModel.current.isTaxable}">
				<h:outputText value="#{detail.deliveredGST}"
					rendered="#{detail.isTaxable}"
					style="font-size:1.2em;color:green;font-weight:bold">
					<f:convertNumber type="number" maxFractionDigits="2"
						minFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column headerText="#{msgs.QST}"
				rendered="#{orderModel.current.isTaxable}">
				<h:outputText value="#{detail.deliveredQST}"
					rendered="#{detail.isTaxable}"
					style="font-size:1.2em;color:green;font-weight:bold">
					<f:convertNumber type="number" maxFractionDigits="2"
						minFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:column headerText="#{msgs.subtotal} +Tax"
				rendered="#{orderModel.current.isTaxable}">
				<h:outputText value="#{detail.deliveredSubTotalPlusTax}"
					style="font-size:1.2em;color:green;font-weight:bold">
					<f:convertNumber type="number" maxFractionDigits="2"
						minFractionDigits="2" />
				</h:outputText>
			</p:column>
			<p:columnGroup type="footer">
				<p:row>
					<p:column colspan="3" footerText="#{msgs.total}"
						style="font-size:1.2em;color:blue;font-weight:bold" />

					<p:column footerText="#{orderModel.current.deliveredQuantityLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column colspan="1"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column colspan="1"
						footerText="#{orderModel.current.deliveredTotalAmountLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column colspan="1" rendered="#{orderModel.current.isTaxable}"
						footerText="#{orderModel.current.deliveredTotalGSTLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column colspan="1" rendered="#{orderModel.current.isTaxable}"
						footerText="#{orderModel.current.deliveredTotalQSTLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
					<p:column colspan="1" rendered="#{orderModel.current.isTaxable}"
						footerText="#{orderModel.current.deliveredTotalAmountLabel}"
						style="font-size:1.2em;color:blue;font-weight:bold" />
				</p:row>
				<p:row>
					<p:column colspan="8" footerText="#{msgs.paidByCredit}"
						rendered="#{orderModel.current.isTaxable}"></p:column>
					<p:column colspan="5" footerText="#{msgs.paidByCredit}"
						rendered="#{!orderModel.current.isTaxable}"></p:column>
					<p:column
						footerText="#{orderModel.current.paidByCreditAmountLabel}"></p:column>
				</p:row>

				<p:row>
					<p:column colspan="8" footerText="#{msgs.charge}"
						rendered="#{orderModel.current.isTaxable}"></p:column>
					<p:column colspan="5" footerText="#{msgs.charge}"
						rendered="#{!orderModel.current.isTaxable}"></p:column>
					<p:column
						footerText="#{orderModel.current.deliveredTotalChargeLabel}"></p:column>
				</p:row>
				<p:row rendered="#{orderModel.current.promotionRewardRate>0}">
					<p:column colspan="8"></p:column>
					<p:column
						footerText="#{orderModel.current.promotionRewardRateLabel} #{msgs.creditReward}"></p:column>
				</p:row>
			</p:columnGroup>
		</p:dataTable>
	</h:panelGrid>
</ui:composition>
</html>